import service2 from "@/utils/request2";
import request from '@/utils/request'
import axios from 'axios'


export const initChunkUpload = (params) => {
  return request({
    url: '/fileSystem/fileUpload/initChunkUpload', method: 'get', params
  })
}

export const mergeChunk = (recordId) => {
  return request({
    url: `/fileSystem/fileUpload/mergeChunk/${recordId}`, method: 'post',
  })
}


export function uploadFileChunkBuffer(data, recordId, index, backData, backFun, setSourceToken, owner) {
  let sourceToken = axios.CancelToken.source()
  setSourceToken(sourceToken, owner)
  return service2.post(`/fileSystem/fileUpload/uploadChunkFile/${recordId}/${index}`, data, {
    cancelToken: sourceToken.token, onUploadProgress(e) {
      backFun(e, backData, data, owner)
    }
  })
}
